# coding: utf-8

'''
http://wiki.it.yzs.io:8090/pages/viewpage.action?pageId=40639911
'''

import sys
import time
from utils.req import *
from utils.jktest import *


def send_post(url, params, jsondump=True, sign=""):
    header = {'Connection' : 'close'}
    r = None
    if jsondump:
        header = {"Content-Type": "application/json; charset=UTF-8", 'Connection': 'close', 'signature':sign}
        r = requests.post(url, data=json.dumps(params), headers=header)
    else:
        r = requests.post(url, data=params, headers=header)
    ret = r.content
    print '-' * 20
    print url
    print params
    print '-' * 20
    print '>>', ret
    return ret

def weather():
    url = "http://%s/unios-skill-service/rest/v1/skill/weather/search" % Server
    signature = "037033c3977d7253645ca3da040aa94737a16ae9"
    params = {"request":{"timstamp":1591152381168,"type":"end","intent":{"slots":[{"isConfirm":"1","isFocus":"0","isMust":"1","name":"province","sort":1,"value":"北京市"},{"isConfirm":"1","isFocus":"0","isMust":"1","name":"city","sort":2,"value":"北京市"},{"isConfirm":"1","isFocus":"0","isMust":"1","name":"cityCode","sort":3,"value":"101010100"},{"isConfirm":"1","isFocus":"0","isMust":"1","name":"topic","sort":4,"value":"RAIN"},{"isConfirm":"1","isFocus":"0","isMust":"1","name":"focusDate","sort":5,"value":"2020-06-04"}],"isConfirm":"1","name":"cn.yunzhisheng.weather.FORECAST"},"info":{"type":"TEXT","recongize":"北京明天下雨吗"}},"session":{"new":"true","attributes":[{"user":"北京明天下雨吗"},{"skill":"北京明天没有雨，天气情况是：晴，-7至5℃，微风(北风)。"}],"sessionId":"7e512f99-6ac6-42d1-a096-44d9ba1b56df"},"context":{"skill":{"skillId":"1badef6a65c44e12a7c6c32a0bc9008c","service":"unios.usk.unisound.weather","skillVersion":"0"},"user":{},"device":{"interfaces":{"vedio":{"formats":[],"codecs":[]},"audio":{"formats":[],"codecs":[]}},"udid":"4093"}},"version":"V1.0"}
    print send_post(url, params, jsondump=True, sign=signature)



if __name__ == '__main__':
    Server = "172.18.10.236:8080" # UAT
    AppKey = "3dcddlnx7ddlb2xatjxtbtxha6xah7iogajzkqie"

    ########### Online #############
    # Server = "172.20.72.3:8080"
    # Server = "172.20.81.241:8080"
    Server = "172.20.7.248:8080"

    weather()
    
    # perf_test()
